package me.zk.practice1.hw;

import java.util.*;

/**
 * @author zhangkai
 * @date 2023/8/14 13:08
 */
public class HWBJJ12 {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();
        scanner.nextLine();
        int[][] data = new int[m][2];
        for (int i = 0; i < m; i++) {
            int[] nums = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            data[i]=nums;
        }
        int start = Integer.parseInt(scanner.nextLine());
        //
        int max = Integer.MIN_VALUE;

        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < data.length; i++) {
            if (data[i][0]==start || data[i][1]==start) {
                list.add(i);
            }
        }

        for (int i = 1; i <=n ; i++) {
            if (i==start) {
                continue;
            }
            int count = Integer.MAX_VALUE;
            //从start出发的的所有节点
            for (int j : list) {
                boolean[] visit = new boolean[m];
                int c = getMin(start,i,visit,data,1,j);
                count = Math.min(c,count);
            }
            max = Math.max(count,max);
        }
        System.out.println(max*2);

    }


    public static int getMin(int start, int end,boolean[] visit,int[][] data,int count,int index) {
        for (int i = index; i < data.length; i++) {
            if (!visit[i]) {
                int[] num = data[i];
                if ((num[0]==start||num[0]==end)&&(num[1]==start||num[1]==end)){
                    return count;
                } else if (num[0]==start||num[1]==start){
                    visit[i]=true;
                    int s = num[0]==start ? num[1]:num[0];
                    return getMin(s,end,visit,data,count+1,0);
                }
            }
        }
        return count;




    }
}
